<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Support;

class Sign
{
    private static $headerSeparator = "\n";
    private static function acsHeaderString(array $headers)
    {
        $array = [];
        foreach ($headers as $headerKey => $headerValue) {
            $key = strtolower($headerKey);
            if(strncmp($key, "x-acs-", 6) === 0) {
                $array[$key] = $headerValue;
            }
        }
        ksort($array);
        $string = "";
        foreach ($array as $sortMapKey => $sortMapValue) {
            $string .= $sortMapKey . ":" . $sortMapValue[0] . self::$headerSeparator;
        }
        return $string;
    }
    private static function resourceString(\Psr\Http\Message\UriInterface $uri)
    {
        return $uri->getPath() . "?" . rawurldecode($uri->getQuery());
    }
    private static function headerString($method, array $headers)
    {
        $string = $method . self::$headerSeparator;
        if(isset($headers["Accept"][0])) {
            $string .= $headers["Accept"][0];
        }
        $string .= self::$headerSeparator;
        if(isset($headers["Content-MD5"][0])) {
            $string .= $headers["Content-MD5"][0];
        }
        $string .= self::$headerSeparator;
        if(isset($headers["Content-Type"][0])) {
            $string .= $headers["Content-Type"][0];
        }
        $string .= self::$headerSeparator;
        if(isset($headers["Date"][0])) {
            $string .= $headers["Date"][0];
        }
        $string .= self::$headerSeparator;
        $string .= self::acsHeaderString($headers);
        return $string;
    }
    private static function percentEncode($string)
    {
        $result = urlencode($string);
        $result = str_replace(["+", "*"], ["%20", "%2A"], $result);
        $result = preg_replace("/%7E/", "~", $result);
        return $result;
    }
    public static function rpcString($method, array $parameters)
    {
        ksort($parameters);
        $canonicalized = "";
        foreach ($parameters as $key => $value) {
            $canonicalized .= "&" . self::percentEncode($key) . "=" . self::percentEncode($value);
        }
        return $method . "&%2F&" . self::percentEncode(substr($canonicalized, 1));
    }
    public static function roaString(\GuzzleHttp\Psr7\Request $request)
    {
        return self::headerString($request->getMethod(), $request->getHeaders()) . self::resourceString($request->getUri());
    }
    public static function uuid($salt)
    {
        return md5($salt . uniqid(md5(microtime(true)), true));
    }
}

?>